package com.newworld.basketballfire.service.controller;

import com.newworld.basketballfire.service.delegate.ActivityServiceDelegate;
import com.newworld.basketballfire.service.exception.ServiceException;
import com.newworld.basketballfire.service.model.Activity;
import com.newworld.basketballfire.service.model.ActivityParams;
import com.newworld.basketballfire.service.model.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by George on 2019/3/31.
 * ActivityService
 */
@RequestMapping(value = "/rest/activity")
@Controller
public class ActivityService {

    @Autowired
    private ActivityServiceDelegate delegate;

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public Activity createActivity(@RequestBody ActivityParams activityParams) throws ServiceException {
        return delegate.createActivity(activityParams);
    }

    @RequestMapping(method = RequestMethod.PUT)
    @ResponseBody
    public Activity updateActivity(@RequestBody ActivityParams activityParams) throws ServiceException {
        return delegate.updateActivity(activityParams.getId(), activityParams);
    }

    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    @ResponseBody
    public Activity updateActivityById(@PathVariable String id, @RequestBody ActivityParams activityParams) throws ServiceException {
        return delegate.updateActivity(id, activityParams);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Activity getActivity(@RequestParam String id) throws ServiceException {
        return delegate.getActivity(id);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    @ResponseBody
    public Activity updateActivityById(@PathVariable String id) throws ServiceException {
        return delegate.getActivity(id);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    @ResponseBody
    public void deleteActivity(@RequestParam String id) throws ServiceException {
        delegate.deleteActivity(id);
    }

    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    @ResponseBody
    public void deleteActivityById(@PathVariable String id) throws ServiceException {
        delegate.deleteActivity(id);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/list")
    @ResponseBody
    public ListResult<Activity> getActivityList(@RequestParam(required = false, defaultValue = "") String id,
                                                @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                @RequestParam(required = false, defaultValue = "10") Integer pageSize) throws ServiceException {
        return delegate.getActivityList(id, pageNo, pageSize);
    }

}
